

package com.rookie.quartz.test.controller;

import com.rookie.quartz.test.entity.ScheduleJobEntity;
import com.rookie.quartz.test.service.ScheduleJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定时任务
 *
 */
@RestController
@RequestMapping("/sys/schedule")
public class ScheduleJobController {
	@Autowired
	private ScheduleJobService scheduleJobService;

	
	/**
	 * 定时任务信息
	 */
	@RequestMapping("/info/{jobId}")
	public ScheduleJobEntity info(@PathVariable("jobId") Long jobId){

		return scheduleJobService.getById(jobId);
	}
	
	/**
	 * 保存定时任务
	 */
	@RequestMapping("/save")
	public int save(@RequestBody ScheduleJobEntity scheduleJob){
		
		scheduleJobService.saveJob(scheduleJob);
		
		return 1;
	}
	
	/**
	 * 修改定时任务
	 */
	@RequestMapping("/update")
	public int update(@RequestBody ScheduleJobEntity scheduleJob){
				
		scheduleJobService.update(scheduleJob);
		
		return 1;
	}
	
	/**
	 * 删除定时任务
	 */
	@RequestMapping("/delete")
	public int delete(@RequestBody Long[] jobIds){
		scheduleJobService.deleteBatch(jobIds);
		
		return 1;
	}
	
	/**
	 * 立即执行任务
	 */
	@RequestMapping("/run")
	public int run(@RequestBody Long[] jobIds){
		scheduleJobService.run(jobIds);
		
		return 1;
	}
	
	/**
	 * 暂停定时任务
	 */
	@RequestMapping("/pause")
	public int pause(@RequestBody Long[] jobIds){
		scheduleJobService.pause(jobIds);
		
		return 1;
	}
	
	/**
	 * 恢复定时任务
	 */
	@RequestMapping("/resume")
	public int resume(@RequestBody Long[] jobIds){
		scheduleJobService.resume(jobIds);
		
		return 1;
	}

}
